package nan.StackAndQueue;

class Node{
    int val;
    Node next;

    public Node(int val) {
        this.val = val;
    }
}
public class MyStack2 {
    //不带傀儡节点的链表
   private Node head=null;
    //1.入栈
    public void push(int val){
        Node newNode=new Node(1);
        //把新节点进行头插
        if(head==null){
            head=newNode;
            return;
        }
        newNode.next=head;
        head=newNode;
    }
    //2.出栈,进行头删
    public Integer pop(){
        if(head==null){
            return null;
        }
        if(head.next==null){
            int ret= head.val;
            head=null;
            return ret;
        }
        int ret= head.val;
        head=head.next;
        return  ret;
    }
    //3.取栈顶
    public Integer peek(){
        if(head==null){
            return null;
        }
        return head.val;
    }
}
